package skins
{
	import flash.display.Graphics;
	import flash.geom.Rectangle;
	
	import mx.charts.ChartItem;
	import mx.charts.chartClasses.GraphicsUtilities;
	import mx.controls.Image;
	import mx.core.BitmapAsset;
	import mx.core.IDataRenderer;
	import mx.core.UIComponent;
	import mx.graphics.IFill;
	import mx.graphics.IStroke;
	import mx.graphics.SolidColor;
	import mx.styles.StyleManager;
	import mx.utils.ColorUtil;

	public class CircleItemRenderer extends UIComponent implements IDataRenderer
	{

        [Embed(source='img/1.gif')]
		private static const imageClass:Class;

		
	/**
	 *  @private
	 */
	private static var rcFill:Rectangle = new Rectangle();


	/**
	 *  @private
	 *  Storage for the data property.
	 */
	private var _chartItem:Object;

	[Inspectable(environment="none")]

	/**
	 *  The chartItem that this itemRenderer displays.
	 *  This value is assigned by the owning series.
	 */
	public function get data():Object
	{
		return _chartItem;
	}
	
	/**
	 *  @private
	 */
	public function set data(value:Object):void
	{
		if (_chartItem == value)
			return;
		_chartItem = value;
	}
		
		private var img:Image;
		
		public function CircleItemRenderer()
		{
			super();
			var bitmapAsset:BitmapAsset = BitmapAsset(new imageClass());
			img = new Image();
			img.source = bitmapAsset;
            addChild(img);
            img.validateNow();
		}
		
	override protected function updateDisplayList(unscaledWidth:Number,
												  unscaledHeight:Number):void
	{
		trace("updateDisplayList", unscaledWidth, " ", unscaledHeight);
		super.updateDisplayList(unscaledWidth, unscaledHeight);
		var fill:IFill;
		var state:String = "";
		
		if(_chartItem is ChartItem && _chartItem.hasOwnProperty('fill'))
		{
		 	fill = _chartItem.fill;
		 	state = _chartItem.currentState;
		}
		else
		 	fill = GraphicsUtilities.fillFromStyle(getStyle('fill'));
		 
        
        var color:uint;
		var adjustedRadius:Number = 0;
		
//		switch(state)
//		{
//			case ChartItem.FOCUSED:
//			case ChartItem.ROLLOVER:
//				if(StyleManager.isValidStyleValue(getStyle('itemRollOverColor')))
//					color = getStyle('itemRollOverColor');
//				else
//					color = ColorUtil.adjustBrightness2(GraphicsUtilities.colorFromFill(fill),-20);
//				fill = new SolidColor(color);
//				adjustedRadius = getStyle('adjustedRadius');
//				if(!adjustedRadius)
//					adjustedRadius = 0;
//				break;
//			case ChartItem.DISABLED:
//				if(StyleManager.isValidStyleValue(getStyle('itemDisabledColor')))
//					color = getStyle('itemDisabledColor');
//				else
//					color = ColorUtil.adjustBrightness2(GraphicsUtilities.colorFromFill(fill),20);
//				fill = new SolidColor(GraphicsUtilities.colorFromFill(color));
//				break;
//			case ChartItem.FOCUSEDSELECTED:
//			case ChartItem.SELECTED:
//				if(StyleManager.isValidStyleValue(getStyle('itemSelectionColor')))
//					color = getStyle('itemSelectionColor');
//				else
//					color = ColorUtil.adjustBrightness2(GraphicsUtilities.colorFromFill(fill),-30);
//				fill = new SolidColor(color);
//				adjustedRadius = getStyle('adjustedRadius');
//				if(!adjustedRadius)
//					adjustedRadius = 0;
//				break;
//		}
//		  
		var stroke:IStroke = getStyle("stroke");
				
		var w:Number = stroke ? stroke.weight / 2 : 0;

//		rcFill.right = unscaledWidth - 8;
//		rcFill.bottom = unscaledHeight - 8;

		var g:Graphics = graphics;
		g.clear();		
//		if (stroke)
//			stroke.apply(g);
//		if (fill)
//			fill.begin(g, rcFill);
//		g.drawEllipse(w - adjustedRadius, w - adjustedRadius, unscaledWidth - 2 * w + adjustedRadius * 2, unscaledHeight - 2 * w + adjustedRadius * 2);
//
//		if (fill)
//			fill.end(g);
		
		img.move((unscaledWidth - img.measuredWidth) / 2, -img.measuredHeight);
		img.setActualSize(img.measuredWidth, img.measuredHeight);
		
	}
		
	}
}